import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Image;
import javax.swing.ImageIcon;
import java.awt.Graphics;
import java.net.URL;

class GetPanel extends JPanel {
	
	private static final long serialVersionUID = 1L;

	int width = 0, hight = 0;

	String imgpath = "";

	public GetPanel(int width, int hight, String file) {
		this.width = width;
		this.hight = hight;
		imgpath = file;
	}

	/**
	 * @author <a href="mailto:shushanlee@msn.com">liss</a>
	 * @param g
	 * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
	 */
	protected void paintComponent(Graphics g) {
		ImageIcon icon = createImageIcon(imgpath);
		Image img = icon.getImage();
		g.drawImage(img, 0, 0, width, hight, this);
	}
	
	public ImageIcon createImageIcon(String path) {
		if (null != path && !"".equals(path)) {
			URL url = this.getClass().getResource(path);
			if (null != url) {
				return new ImageIcon(url);
			} else {
				System.err.println("找不到图片" + path);
				return null;
			}
		}
		return null;
	}
	
	public static void main(String[] args) {
		JPanel jContentPane = new GetPanel(800,675,"63e95ee7t940e9fb8cf27.png");
		JFrame jf = new JFrame();
		jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		jf.setSize(500, 300);
		jf.add(jContentPane);
		jf.setVisible(true);
	}
}